import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:marquee_switcher/marquee_switcher.dart';
import 'package:marquee_vertical_example/RedDot.dart';

SystemUiOverlayStyle light = SystemUiOverlayStyle.dark.copyWith(
    systemNavigationBarIconBrightness: Brightness.dark,
    systemNavigationBarColor: Colors.blue.withOpacity(0),
    systemNavigationBarContrastEnforced: true,
    statusBarColor: Colors.transparent);

void main() {
  runApp(const MyApp());
  SystemChrome.setSystemUIOverlayStyle(light);
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(light);
    return MaterialApp(
        title: 'Demo',
        theme: ThemeData(
          useMaterial3: true,
          primarySwatch: Colors.blue,
          appBarTheme: AppBarTheme(
            systemOverlayStyle: light,
          ),
        ),
        home: const HomePage());
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List<String> texts = [
    "Three BTS members test positive for Covid-19.",
    "The bipartisan friendship that could overcome 'toxic' year in Wash iafaf.",
    "World's most indebted property developer reports progress completi.",
    "Dad, sons and dogs die in fire likely caused by Christmas tree or efafdas.",
  ];
  GlobalKey<MarqueeSwitcherState> key = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // backgroundColor: Colors.black,
      appBar: AppBar(
        title: const Text("Demo"),
      ),
      body: buildListView(),
    );
  }

  Widget buildListView() {
    return ListView.builder(
      itemBuilder: (context, index) => Text('text$index'),
      itemCount: 100,
    );
  }

  Widget buildScrollView() {
    return SingleChildScrollView(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          SizedBox(
            height: 16,
          ),
          MarqueeSwitcher(
            key: key,
            length: texts.length,
            itemBuilder: (_, index) => Text(
              texts[index],
              textAlign: TextAlign.start,
              style: TextStyle(
                color: index % 2 == 0 ? Colors.red : Colors.blue,
              ),
            ),
            onItemTap: (index) {
              print('object$index');
            },
            offsetY: 0.4,
          ),
          SizedBox(
            height: 16,
          ),
          // RedDot(),
          TextButton(
            onPressed: () {
              setState(() {
                texts = [
                  "1234556Dad, sons and dogs die in fire likely caused by Christmas tree or efafdas.",
                  "22233232Three BTS members test positive for Covid-19.",
                  "33333333The bipartisan friendship that could overcome 'toxic' year in Wash i.",
                  "44444444World's most indebted property developer reports progress completi.",
                ];
                // key.currentState?.resetIndex();
              });
            },
            child: Text('变数据'),
          ),
          TextButton(
            onPressed: () {
              setState(() {
                texts.add(
                  "55555555World's most indebted property developer reports progress completi.",
                );
                // key.currentState?.resetIndex();
              });
            },
            child: Text('加一'),
          ),
          TextButton(
            onPressed: () {
              setState(() {
                texts = [
                  "44444Three BTS members test positive for Covid-19.",
                  "333333The bipartisan friendship that could overcome 'toxic' year in Wash iafaf.",
                  "222222World's most indebted property developer reports progress completi.",
                ];
                // key.currentState?.resetIndex();
              });
            },
            child: Text('减一'),
          ),
        ],
      ),
    );
  }
}
